package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.bo.KeywordParam;
import com.cskaoyan.bean.bo.UpdateKeywordBO;
import com.cskaoyan.bean.pojo.MallKeyword;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.bo.KeywordBO;
import com.cskaoyan.bean.vo.KeywordsInfoVO;
import com.cskaoyan.service.KeywordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Chunlai
 * @description: 商场管理的关键字
 * @time: 2021/7/9 11:40
 */
@RestController
@RequestMapping("admin/keyword")
public class KeywordController {

    @Autowired
    KeywordService keywordsService;

    @GetMapping("list")
    @RequiresPermissions("admin:keyword:list")
    public BaseRespVo keywords(KeywordParam param){
        BaseData<MallKeyword> addressBaseData = keywordsService.querykeywordinfos(param);

        return BaseRespVo.ok(addressBaseData);
    }

    @PostMapping("create")
    @RequiresPermissions("admin:keyword:create")
    public BaseRespVo addkeywords(@RequestBody KeywordBO keywordBO){
        if (keywordBO.getUrl() == null){
            return BaseRespVo.fail("url地址不能为空");
        }
        KeywordsInfoVO keywordBaseData =keywordsService.insertkeywordinfos2(keywordBO);
        return BaseRespVo.ok(keywordBaseData);
    }

    @PostMapping("update")
    @RequiresPermissions("admin:keyword:update")
    public BaseRespVo updatewords(@RequestBody UpdateKeywordBO param){
        MallKeyword updatekeyword=keywordsService.updatekeyword(param);
        return BaseRespVo.ok(updatekeyword);
    }

    @PostMapping("delete")
    @RequiresPermissions("admin:keyword:delete")
    public BaseRespVo deletewords(@RequestBody UpdateKeywordBO param){
        keywordsService.delkeyword(param);
        return BaseRespVo.ok();
    }

}